<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file = "lianjie.jsp" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%
		request.setCharacterEncoding("UTF-8");
		String add_id = request.getParameter("id");
		String add_username = request.getParameter("name");
		String add_password = request.getParameter("password");
		String add_kind = request.getParameter("kind");
		String add_sex = request.getParameter("sex");
		String add_tel = request.getParameter("tel");
		int resultNum = 0;
		String sql = "select * from usermassage where id='" + add_id + "'";
		ResultSet rs1 = stmt.executeQuery(sql);
		if(rs1.next()){
			out.println("该编号已存在");
			response.setHeader("Refresh", "3;URL=add_student.jsp");
		}else if(add_username == ""){
			out.println("姓名不能为空！");
			response.setHeader("Refresh", "3;URL=add_student.jsp");
		}else if(add_password == ""){
			out.println("密码不能为空！");
			response.setHeader("Refresh", "3;URL=add_student.jsp");
		}else if(add_kind == ""){
			out.println("类型不能为空");
			response.setHeader("Refresh", "3;URL=add_student.jsp");
		}else if(add_sex == ""){
			out.println("性别不能为空!");
			response.setHeader("Refresh", "3;URL=add_student.jsp");
		}else if(add_tel == ""){
			out.println("联系方式不能为空!");
			response.setHeader("Refresh", "3;URL=add_student.jsp");
		}else{
			String insert_sql = "insert into usermassage(id,username,password,kind,sex,tel) values('"
					+ add_id + "','" + add_username + "','"+add_password + "','" + add_kind + "','" + add_sex + "','" + add_tel + "');";
			
			try {
				stmt.executeUpdate(insert_sql);
			} catch (SQLException e) {
				out.println("错误提示：" + e.getMessage());
			} finally {
				stmt.close();
				conn.close();
			}
			out.println("添加成功");
			response.setHeader("Refresh", "3;URL=teacher.jsp");
		}
	%>
</body>
</html>